<template>
  <div class="search-box">
    <van-icon class="back" name="arrow-left" @click="goBack" />
    <div class="search-container">
      <van-icon class="iconfont" name="search" />
      <input
        class="input"
        type="text"
        title="搜索框"
        placeholder="请输入要搜索的商品"
        v-model="query"
        ref="input"
        @input="toResult"
      />
      <van-icon class="iconfont" name="close" @click="reset" />
    </div>
  </div>
</template>

<script>
import { debounce } from "../../assets/js/util";

export default {
  props: {
    placeholder: {
      type: String,
      default: "请输入搜索内容",
    },
    fake: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      query: "",
    };
  },
  watch: {
    query: debounce(function () {
      this.$emit("query", this.query);
    }),
  },
  methods: {
    focus() {
      this.$refs.input && this.$refs.input.focus();
    },
    clear() {
      this.query = "";
    },
    goBack() {
      this.$router.back();
    },
    reset() {
      this.clear();
      this.focus();
    },
    toResult(){
        
    }
  },
};
</script>

<style scoped>
.search-box {

  display: flex;
  align-items: center;
  width: 100%;
  height: 1rem;
  padding: 1rem 0.2rem 0.2rem;
  font-size: 0.4rem;
  /* background-color: #ccc; */
  box-sizing: border-box;
  border: 1px solid 1px;
  border-radius: 0.5rem;
}
.search-container {
  background: #F7F7F7;
  border-radius: 0.3rem;
  padding: 0.2rem;
}
.input {
  flex: 1;
  background: none;
  border: none;
  margin: 0 0.2rem;
  color: #666;
}

.iconfont {
  color: #ccc;
  font-size: 0.6rem;
  font-weight: bold;
}
.back {
  color: #ccc;
  font-size: 1.1rem;
  margin-right: 0.5rem;
}
</style>
